package stu.aistar.day02;

public class ChangeVarValue {
    public static void main(String[] args) {
        //1. 使用第三方变量
        int a = 10;
        int b = 20;
        int temp = a;
        a = b;
        b = temp;
        System.out.println("a:" + a);
        System.out.println("b:" + b);

        //一个数字连续异或同一个数字俩次结果是它本身.
        int m = 100;
        int n = 200;
        m = m ^ n;//m = 100 ^ 200
        n = m ^ n;//n = 100 ^ 200 ^ 200 = 100
        m = m ^ n;//m = 100 ^ 200 ^ 100 = 200

        System.out.println("m:" + m);
        System.out.println("n:" + n);

        //自创写法(success独家的) - 不推荐写 - 防止菜鸟看不懂
        int x = 100;
        int y = 200;

        //y = 100 ^ 200 ^ 200 = 100
        y = x ^ (x = y) ^ y;

        System.out.println("x:" + x);
        System.out.println("y:" + y);
    }
}
